/**
 * 功能描述
 */
define(function (require, exports, module) {
	var Grid = require("grid");
	var aw = require("ajaxwrapper");
	var Dialog = require("dialog");
	var roomHandler = require("../handler/roomHandler");
	
    var instance = {
        initComponent: function (params, widget) {
        	var grid = new Grid({
        		parentNode : ".J-checkgrid",
        		autoRender: false,
        		model : {
        			url : "api/checkinimplement/queryallcheckinorder",
            		params : function(){
            			var subnav = widget.get("subnav");
            			return {
            				pkServicePoint: subnav.getValue("servicePoint"),
            				"roomStatusIn": subnav.getValue("status"), 
            				startDate : subnav.getValue("startDate").start,
            				endDate : subnav.getValue("startDate").end,
        					fetchProperties:"pkCIImplement,version,roomStatus.*,status.*," +
        							"dataSource.*,signUpNum," + 
        							"nonMemGroupReserve.*,nonMemGroupReserve.nonMemberGroup," + 
        							"nonMemGroupReserve.nonMemberGroup.servicePoint.name," + 
        							"nonMemGroupReserve.nonMemberGroup.*," + 
        							"nonMemGroupReserve.nonMemberGroup.signUps.version," + 
        							"nonMemGroupReserve.nonMemberGroup.operator.servicePoint.name," + 
        							"groupReserve.planItemGroup.allianceOrg.name," +
        							"groupReserve.signUpNumber," +
        							"groupReserve.checkInDate," +
        							"groupReserve.checkOutDate," +
        							"groupReserve.planItemGroup.planItem.destination.name," +
        							"groupReserve.planItemGroup.signUps.version," +
        							"groupReserve.roomRegisters.pkRoomRegister," +
        							"groupReserve.roomRegisters.room.code," +
        							"groupReserve.roomRegisters.room.orgBuilding.name," +
        							"groupReserve.planItemGroup.servicePoint.pkServicePoint," +
        							"groupReserve.planItemGroup.servicePoint.name," +
        							"checkInCar.pkCheckInCar," + 
        							"checkInCar.version," +
        							"checkInCar.haveCar," +
        							"checkInCar.address," + 
        							"checkInCar.status," +
        							"checkInCar.description," +
        							"checkInCar.address," +
        							"checkInCar.carDate," +
        							"checkInDinner.pkCheckInDinner," +
        							"checkInDinner.version," + 
        							"checkInDinner.haveDinner," +
        							"checkInDinner.breakfast," +
        							"checkInDinner.lunch," +
        							"checkInDinner.supper," +
        							"checkInDinner.status," +
        							"checkInDinner.description"
            			}
            		},
        			columns : [{
        				name : "group",
        				label : "团/散客",
        				format : function(value, row){
        					if(row.dataSource.key == "GroupReserve"){
        						return "老人团";
        					}else{
        						return "散客";
        					}
        				}
        			},{
        				name:"groupReserve",
        				label:"组团单位/预约人",
        				format: function(value,row){
        					if(row.dataSource.key == "GroupReserve"){
        						if(value.planItemGroup.allianceOrg){
        							return value.planItemGroup.allianceOrg.name;
        						}else{
        							return value.planItemGroup.servicePoint.name
        						}
        					}else{
        						return row.nonMemGroupReserve.nonMemberGroup.contactName;
        					}
        				}
        			},{
        				name:"destinationName",
        				label:"目的地",
        				format : function(value, row){
        					if(row.dataSource.key == "GroupReserve"){
        						return row.groupReserve.planItemGroup.planItem.destination.name;
        					}else{
        						return row.nonMemGroupReserve.nonMemberGroup.servicePoint == null ? "" : row.nonMemGroupReserve.nonMemberGroup.servicePoint.name;
        					}
        				}
        			},{
        				name:"groupReserve.checkInDate",
        				label:"入住日期",
        				format:function(value,row){
        					if(row.dataSource.key == "GroupReserve"){
        						return moment(value).format("YYYY-MM-DD");
        					}else{
        						return moment(row.nonMemGroupReserve.nonMemberGroup.checkInDate).format("YYYY-MM-DD");
        					}
        				}
        			},{
        				name:"groupReserve.checkOutDate",
        				label:"退住日期",
        				format:function(value,row){
        					if(row.dataSource.key == "GroupReserve"){
        						return moment(value).format("YYYY-MM-DD");
        					}else{
        						return moment(row.nonMemGroupReserve.nonMemberGroup.checkOutDate).format("YYYY-MM-DD");
        					}
        				}
        			},{
        				name:"signUpNum",
        				label:"报名人数",
        			},{
        				name:"roomStatus.value",
        				label:"状态"
        			},{
        				name:"operate",
        				label:"操作",
        				format:"button",
        				formatparams:[{
        					id:"confirm",
        					text:"落实",
        					show: function(value,data){
        						if(data.roomStatus.key == "Pending"){
        							return true;
        						}else{
        							return false;
        						}
        					},
        					handler:function(index,data,rowEle){
        						if(data.status.key=="Edited" || data.status.key=="Initial"){
        							Dialog.alert({
					    				content:"此数据未准备，不得落实！"
					            	});
        						}else{
        							roomHandler.handleSetBtnClick(widget,data);
        						}
//        						roomHandler.handleSetBtnClick(widget,data);
        					}
        				},{
        					id:"check",
        					text:"查看",
        					show: function(value,data){
        						if(data.roomStatus.key == "Pended"){
        							return true;
        						}else{
        							return false;
        						}
        					},
        					handler:function(index,data,rowEle){
        						roomHandler.handleDetailBtnClick(widget,data);
        					}  
        				}]
        			}]
        		}
        	});
        	widget.set("roomBaseGrid", grid);
        }
    };
    module.exports = instance;
});
